import {Directive, Input, TemplateRef, ViewContainerRef} from '@angular/core';

@Directive({
  selector: '[endlessListData]' // Attribute selector
})
export class EndlessListDataDirective {

  constructor(
      public templateRef: TemplateRef<any>,
      public viewContainer: ViewContainerRef
  ) {}

  @Input('endlessListData') set dataSource(data){
      // console.log(data,'data');
      if(data && data.length){
          data.forEach((item,i) => {
              this.viewContainer.createEmbeddedView(this.templateRef,item,i);
          });
      }else{
          this.viewContainer.clear();
      }


  }

}
